package cc.yugu.yhdw.common.domain.hdw;

import cc.yugu.yhdw.common.annotation.Transient;
import cc.yugu.yhdw.common.domain.LongIdEntity;
import cc.yugu.yhdw.common.entity.json.DateTimeSerializer;
import org.codehaus.jackson.map.annotate.JsonSerialize;

import java.util.Date;

/**
 * 换电价格设置
 *
 * @Date:Created in 2018/7/4 9:34
 * @Author:
 * @Modified By: zxj 2018/7/4 9:34
 */
public class ExchangePriceSetting extends LongIdEntity {
    String settingName;
    Integer agentId;
    Long basePriceId;       /*日常套餐*/
    Long activityPriceId;   /*活动套餐*/
    Date activityBeginTime;  /*活动开始时间*/
    Date activityEndTime;   /*活动结束时间*/
    Date createTime;

    // 新添加
    Integer agencyId; // 代理商id

    @Transient
    String basePriceName, activityPriceName, agentName,agencyName;

    public String getBasePriceName() {
        return basePriceName;
    }

    public void setBasePriceName(String basePriceName) {
        this.basePriceName = basePriceName;
    }

    public String getActivityPriceName() {
        return activityPriceName;
    }

    public void setActivityPriceName(String activityPriceName) {
        this.activityPriceName = activityPriceName;
    }

    public String getSettingName() {
        return settingName;
    }

    public void setSettingName(String settingName) {
        this.settingName = settingName;
    }

    public Integer getAgentId() {
        return agentId;
    }

    public void setAgentId(Integer agentId) {
        this.agentId = agentId;
    }
    /* 新增加 */
    public Integer getAgencyId() {
        return agencyId;
    }

    public void setAgencyId(Integer agencyId) {
        this.agencyId = agencyId;
    }

    public Long getBasePriceId() {
        return basePriceId;
    }

    public void setBasePriceId(Long basePriceId) {
        this.basePriceId = basePriceId;
    }

    public Long getActivityPriceId() {
        return activityPriceId;
    }

    public void setActivityPriceId(Long activityPriceId) {
        this.activityPriceId = activityPriceId;
    }

    @JsonSerialize(using = DateTimeSerializer.class)
    public Date getActivityBeginTime() {
        return activityBeginTime;
    }

    public void setActivityBeginTime(Date activityBeginTime) {
        this.activityBeginTime = activityBeginTime;
    }

    @JsonSerialize(using = DateTimeSerializer.class)
    public Date getActivityEndTime() {
        return activityEndTime;
    }

    public void setActivityEndTime(Date activityEndTime) {
        this.activityEndTime = activityEndTime;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getAgentName() {
        return agentName;
    }

    public void setAgentName(String agentName) {
        this.agentName = agentName;
    }

    public String getAgencyName() {
        return agencyName;
    }

    public void setAgencyName(String agencyName) {
        this.agencyName = agencyName;
    }

    /**
     * 获取设置的换电价格（判断执行换电的价格）
     * @Param []
     * @Return java.lang.Long
     * @Author zxj 2018/7/4
     */
    public Long getUsedPriceId() {
        if(activityPriceId == null) {
            return basePriceId;
        }
        if(activityBeginTime == null && activityEndTime == null) {
            return activityPriceId;
        }
        if(activityBeginTime != null && activityEndTime == null) {
            return System.currentTimeMillis() >= activityBeginTime.getTime() ? activityPriceId : basePriceId;
        }
        if(activityBeginTime == null && activityEndTime != null) {
            return System.currentTimeMillis() <= activityEndTime.getTime() ? activityPriceId : basePriceId;
        }
        if(activityBeginTime != null && activityEndTime != null) {
            return System.currentTimeMillis() >= activityBeginTime.getTime() && System.currentTimeMillis() <= activityEndTime.getTime() ? activityPriceId : basePriceId;
        }
        return basePriceId;
    }
}
